package com.huluobo.day_1_lifecycledemo.viewmodel;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.huluobo.day_1_lifecycledemo.R;

public class HomeFragment extends Fragment {

    private ShareDataViewModel shareDataViewModel;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_home, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        shareDataViewModel = new ViewModelProvider(this).get(ShareDataViewModel.class);

        shareDataViewModel.setPosition(2);//往viewModel中存值
    }
}